// 这里用于编写与页面紧密相连的扩展函数
const ViewUtil = {};
// 该方法可以更新导航栏
ViewUtil.NavTouch = {
  // 切换页面
  changPage: function (swiper) {
    $(".nav-core").fadeIn();
    $(".music-coll").css("width", "75%");
    $("#tarr").css("width", "200px");
    let index = swiper.activeIndex;
    if (index == 1) {
      swiper.allowSlidePrev = false;
    } else {
      swiper.allowSlidePrev = true;
    }
    swiper.slideTo(index);
    if (index == 1) {
      $(".ico-mod > img").attr("src", "images/icon/cli-mod.svg");
      $(".ico-user > img").attr("src", "images/icon/uns-user.svg");
    } else if (index == 2) {
      $(".ico-mod > img").attr("src", "images/icon/uns-mod.svg");
      $(".ico-user > img").attr("src", "images/icon/cli-user.svg");
    } else {
      $(".nav-core").fadeOut(150);
      $(".music-coll").css("width", "100%");
      $("#tarr").css("width", "400px");
    }
  },
};
// 对音乐播放容器的更新
ViewUtil.MusicColl = {
  // 依赖用flag
  isAnimeing: false,
  // 更新小音乐
  updataSM: function (name, img, audio, sing) {
    $(".mus-kbd > img").attr("src", "icons/play.svg");
    $(".mus-img > img").attr("src", img);
    $(".mus-name").text(name);
    $(".mpadc-song > p").text(name);
    $(".mpadc-sing > p").text(sing);
    ViewUtil.Rond.rondMPlayer(img, audio);
  },
  // 旋转
  roat: function (played) {
    if (played) {
      $(".mus-img").css("animation-play-state", "running");
    } else {
      $(".mus-img").css("animation-play-state", "paused");
    }
  },
  // 展开音乐播放器
  MPlayer(isopen) {
    if (isopen) {
      if (this.isAnimeing) return;
      this.isAnimeing = true;
      $(".music-player").css("display", "block");
      $(".music-player").addClass("animate__fadeInUpBig");
      $(".application-core").addClass("animate__fadeOutUpBig");
      $(".music-player").removeClass("animate__fadeOutDownBig");
      $(".application-core").removeClass("animate__fadeInDown");
      setTimeout(function () {
        $(".application-core").css("display", "none");
        ViewUtil.MusicColl.isAnimeing = false;
      }, 400);
    } else {
      if (this.isAnimeing) return;
      this.isAnimeing = true;
      $(".application-core").css("display", "block");
      $(".application-core").removeClass("animate__fadeOutUpBig");
      $(".music-player").removeClass("animate__fadeInUpBig");
      $(".music-player").addClass("animate__fadeOutDownBig");
      $(".application-core").addClass("animate__fadeInDown");
      setTimeout(function () {
        $(".music-player").css("display", "none");
        ViewUtil.MusicColl.isAnimeing = false;
      }, 400);
    }
  },
};
// 渲染数据
ViewUtil.Rond = {
  // 渲染列表数据
  rondArray(cdata) {
    $(".sear-list-coll").html("");
    cdata.forEach((value) => {
      $(".sear-list-coll").append(`
        <div class="music-coller" data-n="${value.n}">
          <span>${value.title}</span>
          <p>${value.singer}</p>
        </div>
      `);
    });
  },
  // 歌名渲染切换
  rondSName(now, next, sing) {
    let last = GroupVariable.NowMusicId;
    if (last < 0) {
      return;
    }
    if (now != null) $(".mpadc-song > p").text(now);
    if (sing) $(".mpadc-sing > p").text(sing);
    last = GroupVariable.MusicList[last - 1].song;
    switch (GroupVariable.PlayIndex) {
      case 0:
        if (now != null) $(".n0").text(now);
        $(".n2").text(last);
        if (next != null) $(".n1").text(next);
        break;
      case 1:
        if (now != null) $(".n1").text(now);
        $(".n0").text(last);
        if (next != null) $(".n2").text(next);
        break;
      case 2:
        if (now != null) $(".n2").text(now);
        $(".n1").text(last);
        if (next != null) $(".n0").text(next);
        break;
    }
  },
  // 渲染播放器
  rondMPlayer(mus_bg, audio) {
    if (mus_bg != null) {
      $(".music-player").css("background-image", "url(" + mus_bg + ")");
      $(".mpadc-fm > img").attr("src", mus_bg);
    }
    if (audio.paused) {
      $(".mcc-pp > img").attr("src", "icons/pause.svg");
    } else {
      $(".mcc-pp > img").attr("src", "icons/play.svg");
    }
  },
  // 渲染播放列表
  rondMList(datas, type) {
    GroupVariable.PlayListSwiper.removeAllSlides();
    let i = 0;
    if (type == GroupEnum.ModEnum.SEARCH_LIST) {
      datas.forEach((data) => {
        GroupVariable.PlayListSwiper.appendSlide(`
          <div class="swiper-slide music_list_slide" data-niid="${i}">
            <img src="${data.cover}">
            <p>${data.title}</p>
          </div>
        `);
        i++;
      });
    } else {
      datas.forEach((data) => {
        GroupVariable.PlayListSwiper.appendSlide(`
          <div class="swiper-slide music_list_slide" data-niid="${i}">
            <img src="${data.img}">
            <p>${data.song}</p>
          </div>
        `);
        i++;
      });
    }
  }
};
